//
//  DrawerView.m
//  BeanSproutEDU
//
//  Created by douya on 15/1/6.
//  Copyright (c) 2015年 douya. All rights reserved.
//

#import "DrawerView.h"

@implementation DrawerView
+(DrawerView *)createDrawer
{
    
    
    DrawerView *drawer=[[DrawerView alloc] init];
    
//    drawer.backgroundColor=[UIColor colorWithRed:40/255.0 green:170/255.0 blue:82/255.0 alpha:1];
    
    UIImageView *headImageView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
    headImageView.image=[UIImage imageNamed:@"douyaHead.jpg"];
    [drawer addSubview:headImageView];
    
    UILabel *nickName=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+10, 30, 150, 30)];
    nickName.text=@"小豆芽";
    [drawer addSubview:nickName];
    
    UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headImageView.frame)+10, 200, 200) style:UITableViewStylePlain];
    tableView.bounces=NO;
    tableView.separatorColor=[UIColor blackColor];//将分离线设置为黑色  不然当cell透明时 就看不见分离线
    tableView.backgroundColor=[UIColor clearColor];
    tableView.delegate=drawer;
    tableView.dataSource=drawer;
    [drawer addSubview:tableView];
    
    return drawer;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSArray *btnNameArr=[NSArray arrayWithObjects:@"全部课程",@"我的课程",@"个人资料",@"充值/余额" ,nil];
   static NSString *ID=@"indentifier";
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];

    if (!cell)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.textLabel.text=[btnNameArr objectAtIndex:indexPath.row];
    
    
    return cell;
    
}

//将单元格设置为透明  必须调用此方法 否则再怎么设置 cell都是白色的
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor=[UIColor clearColor];
    cell.separatorInset=UIEdgeInsetsMake(0, 0, 0, 0);
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str=[NSString stringWithFormat:@"%zd",indexPath.row];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeView" object:str];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
